import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/ShopPage/UserMainPage01.dart';
import 'package:BeeApp/ShopPage/UserMainPage02.dart';
import 'package:BeeApp/ShopPage/UserMainPage03.dart';
import 'package:BeeApp/ShopPage/UserNewsPage.dart';
import 'package:flutter/material.dart';

class MainShopUserPage extends StatefulWidget {
  MainShopUserPage({Key key}) : super(key: key);

  @override
  _MainShopUserPageState createState() => _MainShopUserPageState();
}

class _MainShopUserPageState extends State<MainShopUserPage> {
  TabController _controller;
  List pages = [UserMainPage01(), UserMainPage02(), UserMainPage03()];
  int selectPage = 0;

  @override
  void initState() {
    super.initState();
    _controller = TabController(
      length: pages.length,
      vsync: ScrollableState(),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller?.removeListener(() {});
    _controller?.dispose();
  }

  TextStyle textStyle01(int index) {
    if (index == selectPage) {
      return TextStyle(
        color: Color(0xFF333333),
        fontSize: setFontSize(36),
      );
    } else {
      return TextStyle(
        color: Color(0xFFCBCBCB),
        fontSize: setFontSize(34),
      );
    }
  }

  Widget _getTabbar() {
    return Expanded(
      child: TabBar(
        controller: _controller,
        indicatorColor: Colors.black,
        labelPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
        indicatorWeight: 4,
        indicatorSize: TabBarIndicatorSize.label,
        indicatorPadding: EdgeInsets.only(left: 20, right: 20),
        // isScrollable: true,
        onTap: (value) {
          setState(() {
            selectPage = value;
          });
        },
        tabs: <Widget>[
          Text("同城物流", style: textStyle01(0)),
          RichText(
            text: TextSpan(children: <InlineSpan>[
              TextSpan(text: '国内', style: textStyle01(1)),
              TextSpan(
                  text: '(同城)',
                  style: TextStyle(
                      color: selectPage == 1
                          ? Color(0xFF333333)
                          : Color(0xFFCBCBCB),
                      fontSize: setFontSize(20))),
              TextSpan(text: '专运', style: textStyle01(1)),
            ]),
          ),
          Text("我的订单", style: textStyle01(2)),
        ],
      ),
    );
  }

  Widget _getTabview() {
    return TabBarView(
      controller: _controller,
      children: <Widget>[
        UserMainPage01(),
        UserMainPage02(),
        UserMainPage03(),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: PreferredSize(
        preferredSize: Size(0, 0),
        child: AppBar(
          elevation: 0,
        ),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Container(
              alignment: Alignment.topLeft,
              child: Row(
                children: <Widget>[
                  IconButton(
                    icon: Image.asset(
                      "images/MainUserImage.png",
                      height: 15,
                      width: 15,
                    ),
                    onPressed: () {
                      Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => UserNewsPage()));
                    },
                  ),
                  _getTabbar(),
                ],
              ),
            ),
            Expanded(child: _getTabview()),
          ],
        ),
      ),
    );
  }
}
